library(spatstat)
library(here)
library(sp)
library(rgeos)
library(maptools)
library(GISTools)
library(tmap)
library(sf)
library(geojson)
library(geojsonio)
library(tmaptools)
library(stringr)
library(tidyverse)
library(spdep)
library(raster)
library(fpc)
library(dbscan)
library(OpenStreetMap)
library(png)
library(rmarkdown)
#reading wards
LondonWards <- st_read(here::here("data", "London-wards-2018_ESRI", "London_Ward.shp"))
## Reading layer `London_Ward' from data source `D:\OneDrive\UCL\Work\GIS\GIS-coursework\Data\Cutural infrastructures\data\London-wards-2018_ESRI\London_Ward.shp' using driver `ESRI Shapefile'
## Simple feature collection with 657 features and 6 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: 503568.2 ymin: 155850.8 xmax: 561957.5 ymax: 200933.9
## projected CRS: OSGB 1936 / British National Grid
LondonWardsMerged <- st_read(here::here("data", "London-wards-2018_ESRI",
"London_Ward_CityMerged.shp"))%>%
st_transform(.,27700)
## Reading layer `London_Ward_CityMerged' from data source `D:\OneDrive\UCL\Work\GIS\GIS-coursework\Data\Cutural infrastructures\data\London-wards-2018_ESRI\London_Ward_CityMerged.shp' using driver `ESRI Shapefile'
## Simple feature collection with 633 features and 6 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: 503568.2 ymin: 155850.8 xmax: 561957.5 ymax: 200933.9
## projected CRS: OSGB 1936 / British National Grid
#reading pubs
Pubs <- read_csv("data/Pubs.csv",na = c("NA", "n/a"))
Pubs_spatial <- sf::st_as_sf(Pubs, coords = c("longitude", "latitude"), crs = 4326) %>%
st_transform(.,27700)
qtm(LondonWardsMerged)

qtm(Pubs_spatial)

#change the ward name to code
#library(plyr)
#df <- data.frame(foo=norm(1000))
#df <- rename(df,c('foo'='samples'))
names(Pubs_spatial)[names(Pubs_spatial) == 'ward_2018_code'] <- 'GSS_CODE'
names(Pubs_spatial)[names(Pubs_spatial) == 'ward_2018_name'] <- 'NAME'
#join data
#LondonWardsMerged_Pub <- LondonWardsMerged
Pubs_spatial <- Pubs_spatial %>%
add_count(GSS_CODE, name="Pubs_in_ward")
#don't know how to join the don't Let's do it
Pubs_sub <- Pubs_spatial[LondonWardsMerged,]
tmap_mode("view")
tm_shape(LondonWardsMerged) +
tm_polygons(col = NA, alpha = 0.5) +
tm_shape(Pubs_sub) +
tm_dots(col = "blue")